package JDBC.dao;

import JDBC.pojo.Person;
import JDBC.tool.DbOpenHelper;

import java.util.ArrayList;
import java.util.List;

/**
 * @time: 2021/2/4/004 11:18
 * @author: Zhurunhe
 */
public class UserDao extends DbOpenHelper {

    //查询所有用户信息
    public List<Person> getAllUserInfo(){
        List<Person> list=new ArrayList<>();
        try{
            getConnection();//连接数据库
            String sql="select * from userInfo ";
            pstmt=conn.prepareStatement(sql);
            rs=pstmt.executeQuery();
            while(rs.next()){
                Person item=new Person();
                item.setP_id(rs.getInt("id"));
                item.setP_name(rs.getString("name"));
                item.setP_pwd(rs.getString("pwd"));
                list.add(item);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            closeAll();//关闭数据库连接
        }
        return list;
    }
}
